/**
 * Project: daycare-war
 * Package: com.made2ordersoftware.daycare.service
 * File: PersonDao
 * Created: Dec 11, 2010
 */
/**
 * Copyright (c) 2010 Made 2 Order Software, LLC
 *
 * All rights reserved. No part of this software may be reproduced, stored in a retrieval system, or
 * transmitted in any form or by any means, without the prior written permission of Made 2 Order Software.
 *
 * You may not distribute the URL or redistribute the files to third parties. You may transfer the files onto
 * a single storage device so long as you can prove ownership of the software. You may not reverse engineer,
 * decompile, or disassemble the software or media files. You may not modify or translate the software or
 * media, or distribute copies of the software or media without the written consent of Made 2 Order Software,
 * LLC.
 */
package com.made2ordersoftware.daycare.service;

import com.made2ordersoftware.daycare.domain.PersonEntity;
import com.made2ordersoftware.exceptions.DAOException;
import com.made2ordersoftware.service.AbstractDao;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Data Access Object for all person activities of the system.
 *
 * @author David Canning <dcannin@gmail.com>
 * @version 1.0.0
 */
@Stateless
public class PersonDao extends AbstractDao<PersonEntity, Long> {

    private static final Logger LOG = LoggerFactory.getLogger(PersonDao.class);
    private static final long serialVersionUID = 1L;
    @PersistenceContext(unitName = "daycare_pu")
    private EntityManager em;

    /**
     * Creates an instance of <code>PersonDao</code>.
     */
    public PersonDao() {
        super(PersonEntity.class);
    }

    /**
     * Get a list of all IDs from person table.
     *
     * @return
     *
     * @throws DAOException
     */
    public List<Long> findPersonIDs() throws DAOException {
        LOG.info("Start find all person IDs");
        Query sql = em.createNamedQuery("Person.findIDs");
        try {
            List<Long> IDs = sql.getResultList();
            LOG.info("Finish findPersonIDs...");
            return IDs;
        } catch (Exception e) {
            throw new DAOException(
                    "com.made2ordersoftware.daycare.service:PersonDao:findPersonIDs:"
                    + e.getCause() + ":Unexpected server error");
        }
    }

    /**
     * Returns the EntityManager for the dao.
     *
     * @return the em
     */
    @Override
    protected EntityManager getEntityManager() {
        LOG.info("Getting entity manager....");
        return em;
    }

}
